home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1996
/
MacHack 1996.toast
/
Presentations
/
Presentations ’91
/
DAL Files
/
DALtool 4⁄19 (System 6.x)
/
DalHandlers.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-19
|
6KB
|
327 lines
#include "DalDemo.h"
extern EventRecord gTheEvent;
extern Boolean gDone;
extern char dirty;
extern Rect gDragRect;
extern MenuHandle gAppleMenu, gFileMenu, gEditMenu;
extern Boolean gDALActive, gDALMonitor;
extern int gDALState;
/*** HandleIdle ***/
HandleIdle()
{
WindowPtr aWind;
int aType;
aWind = FrontWindow();
aType = (int) WindowType(aWind);
if (aType == DEMO_WINDOW)
{
TEIdle(((demoPeek)aWind)->curTE);
if (gDALActive) DALMonitorState((demoPeek)aWind);
}
}
/*** HandleEvent ***/
HandleEvent()
{
char theChar;
Boolean inBackground;
switch (gTheEvent.what)
{
case nullEvent:
HandleIdle();
break;
case mouseDown:
HandleMouseDown();
break;
case keyDown:
case autoKey:
theChar = gTheEvent.message & charCodeMask;
if ((gTheEvent.modifiers & cmdKey) != 0)
{
AdjustMenus();
HandleMenuChoice(MenuKey(theChar));
}
else
HandleTEKey(theChar);
break;
case activateEvt:
HandleActivate((WindowPtr)gTheEvent.message, (gTheEvent.modifiers & activeFlag) != 0);
break;
case updateEvt:
HandleUpdate((WindowPtr)gTheEvent.message);
break;
case app4Evt:
if ((gTheEvent.message & SUSPEND_RESUME_BIT) == RESUMING)
{
inBackground = (gTheEvent.message & 0x01) == 0;
HandleActivate(FrontWindow(), !inBackground);
}
else
HandleIdle();
break;
}
}
/*** HandleUpdate ***/
HandleUpdate(w)
WindowPtr w;
{
GrafPtr savePort;
GetPort( &savePort );
SetPort( w );
BeginUpdate( w );
EraseRect(&w->portRect);
DrawDemoWind(w);
EndUpdate( w );
SetPort( savePort );
}
/*** HandleMouseDown ***/
HandleMouseDown()
{
WindowPtr whichWindow;
short int thePart;
long int menuChoice,windSize;
thePart = FindWindow(gTheEvent.where, &whichWindow);
switch (thePart)
{
case inMenuBar:
AdjustMenus();
menuChoice = MenuSelect( gTheEvent.where);
HandleMenuChoice(menuChoice);
break;
case inSysWindow:
SystemClick(&gTheEvent,whichWindow);
break;
case inDrag:
DragWindow(whichWindow, gTheEvent.where, &gDragRect);
break;
case inGoAway:
if (TrackGoAway(whichWindow, gTheEvent.where))
HandleCloseWindow((demoPeek)whichWindow);
break;
case inContent:
if (whichWindow != FrontWindow())
SelectWindow(whichWindow);
else
DoContent(whichWindow, &gTheEvent);
break;
}
}
/*** AdjustMenus ***/
AdjustMenus()
{
WindowPtr window;
int wType;
int offset;
TEHandle te;
window = FrontWindow();
wType = WindowType(window);
if (window == NIL)
{
DisableItem(gFileMenu,CLOSE_ITEM);
CheckItem(gFileMenu, MONITOR_ITEM,FALSE);
DisableItem(gFileMenu,MONITOR_ITEM);
EnableItem(gFileMenu,NEW_ITEM);
DisableItem(gEditMenu,UNDO_ITEM);
DisableItem(gEditMenu,CUT_ITEM);
DisableItem(gEditMenu,COPY_ITEM);
DisableItem(gEditMenu,PASTE_ITEM);
DisableItem(gEditMenu,CLEAR_ITEM);
}
else if (wType == DA_WINDOW)
{
DisableItem(gFileMenu,CLOSE_ITEM);
EnableItem(gEditMenu,UNDO_ITEM);
EnableItem(gEditMenu,CUT_ITEM);
EnableItem(gEditMenu,COPY_ITEM);
EnableItem(gEditMenu,PASTE_ITEM);
EnableItem(gEditMenu,CLEAR_ITEM);
}
else if (wType == DEMO_WINDOW)
{
EnableItem( gFileMenu, CLOSE_ITEM);
EnableItem( gFileMenu, MONITOR_ITEM);
DisableItem( gFileMenu, NEW_ITEM);
DisableItem(gEditMenu,UNDO_ITEM);
DisableItem(gEditMenu,CUT_ITEM);
DisableItem(gEditMenu,COPY_ITEM);
DisableItem(gEditMenu,PASTE_ITEM);
DisableItem(gEditMenu,CLEAR_ITEM);
te = ((demoPeek)window)->curTE;
if ( (*te)->selStart < (*te)->selEnd)
{
EnableItem(gEditMenu,CUT_ITEM);
EnableItem(gEditMenu,COPY_ITEM);
EnableItem(gEditMenu,CLEAR_ITEM);
}
if ( GetScrap(NIL, 'TEXT', &offset) > 0)
EnableItem(gEditMenu,PASTE_ITEM);
}
}
/*** HandleMenuChoice ***/
HandleMenuChoice(menuChoice)
long int menuChoice;
{
int theMenu;
int theItem;
if (menuChoice != 0)
{
theMenu = HiWord(menuChoice);
theItem = LoWord(menuChoice);
switch (theMenu)
{
case APPLE_MENU_ID:
HandleAppleChoice(theItem);
break;
case FILE_MENU_ID:
HandleFileChoice(theItem);
break;
case EDIT_MENU_ID:
HandleEditChoice(theItem);
break;
}
HiliteMenu(0);
}
}
/*** HandleAppleChoice ***/
HandleAppleChoice (theItem)
int theItem;
{
Str255 accName;
int accNumber;
switch (theItem)
{
case ABOUT_ITEM:
NoteAlert(ABOUT_ALERT, NIL);
break;
default:
GetItem(gAppleMenu, theItem, accName);
accNumber = OpenDeskAcc(accName);
break;
}
}
/*** HandleFileChoice ***/
HandleFileChoice(theItem)
int theItem;
{
WindowPtr whichWindow;
switch ( theItem)
{
case NEW_ITEM:
CreateSession();
break;
case CLOSE_ITEM:
if ((whichWindow = FrontWindow()) != NIL)
HandleCloseWindow((demoPeek)whichWindow);
gDALMonitor = FALSE;
break;
case MONITOR_ITEM:
gDALMonitor ^= TRUE;
CheckItem(gFileMenu, MONITOR_ITEM,gDALMonitor);
break;
case QUIT_ITEM:
if ((whichWindow = FrontWindow()) != NIL)
HandleCloseWindow((demoPeek)whichWindow);
gDALMonitor = FALSE;
gDone = TRUE;
break;
}
}
/*** HandleEditChoice ***/
HandleEditChoice( theItem)
int theItem;
{
TEHandle te;
WindowPtr window;
int wType, length, i;
CharsHandle text;
Str255 tempStr;
demoPeek demoWind;
if (!SystemEdit (theItem - 1))
{
window = FrontWindow();
wType = WindowType(window);
if (wType == DEMO_WINDOW)
{
demoWind = (demoPeek) window;
te = demoWind->curTE;
switch (theItem)
{
case UNDO_ITEM:
break;
case CUT_ITEM:
if (ZeroScrap() == noErr)
{
TECut(te);
AdjustScrollBar(demoWind);
if (TEToScrap() != noErr)
ZeroScrap();
}
break;
case COPY_ITEM:
if (ZeroScrap() == noErr)
{
TECopy(te);
if (TEToScrap() != noErr)
ZeroScrap();
}
break;
case PASTE_ITEM:
if (TEFromScrap() == noErr)
{
TEPaste(te);
AdjustScrollBar(demoWind);
}
break;
case CLEAR_ITEM:
TEDelete(te);
AdjustScrollBar(demoWind);
break;
} /* switch */
} /* if my wType */
} /* !SystemEdit */
} /*HandleEditChoice*/
/*** ErrorHandler ***/
ErrorHandler(strNum)
int strNum;
{
StringHandle errStrH;
if ((errStrH = GetString(strNum)) == NIL)
ParamText(FATAL_STR,NIL,NIL,NIL);
else
{
HLock(errStrH);
ParamText(*errStrH,NIL,NIL,NIL);
HUnlock(errStrH);
}
StopAlert(ERROR_ALERT_ID,NIL);
ExitToShell();
}